{
  "nbformat": 4,
  "nbformat_minor": 0,
  "metadata": {
    "colab": {
      "provenance": []
    },
    "kernelspec": {
      "name": "python3",
      "display_name": "Python 3"
    },
    "language_info": {
      "name": "python"
    }
  },
  "cells": [
    {
      "cell_type": "code",
      "source": [
        "import subprocess\n",
        "import sys\n",
        "import os\n",
        "\n",
        "def install_packages():\n",
        "    \"\"\"Install required packages in Colab\"\"\"\n",
        "    packages = [\n",
        "        \"crewai\",\n",
        "        \"crewai-tools\",\n",
        "        \"google-generativeai\",\n",
        "        \"python-dotenv\",\n",
        "        \"langchain-google-genai\"\n",
        "    ]\n",
        "\n",
        "    for package in packages:\n",
        "        try:\n",
        "            print(f\"📦 Installing {package}...\")\n",
        "            subprocess.check_call([sys.executable, \"-m\", \"pip\", \"install\", package, \"-q\"])\n",
        "            print(f\"✅ {package} installed successfully!\")\n",
        "        except Exception as e:\n",
        "            print(f\"❌ Failed to install {package}: {e}\")\n",
        "\n",
        "print(\"🚀 Setting up Google Colab environment...\")\n",
        "install_packages()\n",
        "print(\"✅ All packages installed!\")"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "DrunepXKpST9",
        "outputId": "b8a10cee-b3f6-4757-bdd3-258c4712a76d"
      },
      "execution_count": 6,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "🚀 Setting up Google Colab environment...\n",
            "📦 Installing crewai...\n",
            "✅ crewai installed successfully!\n",
            "📦 Installing crewai-tools...\n",
            "✅ crewai-tools installed successfully!\n",
            "📦 Installing google-generativeai...\n",
            "✅ google-generativeai installed successfully!\n",
            "📦 Installing python-dotenv...\n",
            "✅ python-dotenv installed successfully!\n",
            "📦 Installing langchain-google-genai...\n",
            "✅ langchain-google-genai installed successfully!\n",
            "✅ All packages installed!\n"
          ]
        }
      ]
    },
    {
      "cell_type": "code",
      "source": [
        "import warnings\n",
        "warnings.filterwarnings('ignore')\n",
        "\n",
        "from crewai import Agent, Task, Crew, Process\n",
        "from crewai_tools import FileReadTool\n",
        "from langchain_google_genai import ChatGoogleGenerativeAI\n",
        "import google.generativeai as genai\n",
        "from google.colab import userdata\n",
        "import time\n",
        "import json\n",
        "from datetime import datetime"
      ],
      "metadata": {
        "id": "Psi5o7AKuupZ"
      },
      "execution_count": 7,
      "outputs": []
    },
    {
      "cell_type": "code",
      "source": [
        "def setup_api_key():\n",
        "    \"\"\"Setup Gemini API key in Colab\"\"\"\n",
        "    try:\n",
        "        api_key = userdata.get('GEMINI_API_KEY')\n",
        "        print(\"✅ API key loaded from Colab secrets!\")\n",
        "        return api_key\n",
        "    except:\n",
        "        print(\"🔑 Gemini API key not found in Colab secrets.\")\n",
        "        print(\"Please follow these steps:\")\n",
        "        print(\"1. Go to https://makersuite.google.com/app/apikey\")\n",
        "        print(\"2. Create a free API key\")\n",
        "        print(\"3. In Colab, go to 🔑 (Secrets) in the left sidebar\")\n",
        "        print(\"4. Add a new secret named 'GEMINI_API_KEY' with your API key\")\n",
        "        print(\"5. Enable notebook access for the secret\")\n",
        "        print(\"6. Re-run this cell\")\n",
        "\n",
        "        from getpass import getpass\n",
        "        api_key = getpass(\"Or enter your Gemini API key here (it will be hidden): \")\n",
        "        return api_key\n",
        "\n",
        "GEMINI_API_KEY = setup_api_key()"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "8vWyuN34uvvc",
        "outputId": "a58aa654-ab13-4b04-ceda-8f5e164f4222"
      },
      "execution_count": 8,
      "outputs": [
        {
          "name": "stdout",
          "output_type": "stream",
          "text": [
            "🔑 Gemini API key not found in Colab secrets.\n",
            "Please follow these steps:\n",
            "1. Go to https://makersuite.google.com/app/apikey\n",
            "2. Create a free API key\n",
            "3. In Colab, go to 🔑 (Secrets) in the left sidebar\n",
            "4. Add a new secret named 'GEMINI_API_KEY' with your API key\n",
            "5. Enable notebook access for the secret\n",
            "6. Re-run this cell\n",
            "Or enter your Gemini API key here (it will be hidden): ··········\n"
          ]
        }
      ]
    },
    {
      "cell_type": "code",
      "source": [
        "class ColabGeminiAgentSystem:\n",
        "    def __init__(self, api_key):\n",
        "        \"\"\"Initialize the Colab-optimized Gemini agent system\"\"\"\n",
        "        self.api_key = api_key\n",
        "        self.setup_gemini()\n",
        "        self.setup_tools()\n",
        "        self.setup_agents()\n",
        "        self.results_history = []\n",
        "\n",
        "    def setup_gemini(self):\n",
        "        \"\"\"Configure Gemini API for Colab\"\"\"\n",
        "        try:\n",
        "            genai.configure(api_key=self.api_key)\n",
        "\n",
        "            model = genai.GenerativeModel('gemini-1.5-flash')\n",
        "            response = model.generate_content(\"Hello, this is a test.\")\n",
        "            print(\"✅ Gemini API connection successful!\")\n",
        "\n",
        "            self.llm = ChatGoogleGenerativeAI(\n",
        "                model=\"gemini-1.5-flash\",\n",
        "                google_api_key=self.api_key,\n",
        "                temperature=0.7,\n",
        "                convert_system_message_to_human=True\n",
        "            )\n",
        "\n",
        "        except Exception as e:\n",
        "            print(f\"❌ Gemini API setup failed: {str(e)}\")\n",
        "            raise\n",
        "\n",
        "    def setup_tools(self):\n",
        "        \"\"\"Initialize available tools\"\"\"\n",
        "        self.file_tool = FileReadTool()\n",
        "        print(\"🛠️ Tools initialized successfully!\")\n",
        "\n",
        "    def setup_agents(self):\n",
        "        \"\"\"Create specialized agents optimized for Colab\"\"\"\n",
        "\n",
        "        self.researcher = Agent(\n",
        "            role=\"Senior Research Analyst\",\n",
        "            goal=\"Conduct comprehensive research and provide detailed insights\",\n",
        "            backstory=\"\"\"You are an expert research analyst with extensive experience in\n",
        "            gathering, analyzing, and synthesizing information. You excel at identifying\n",
        "            key trends, patterns, and providing actionable insights.\"\"\",\n",
        "            llm=self.llm,\n",
        "            tools=[self.file_tool],\n",
        "            verbose=True,\n",
        "            allow_delegation=False,\n",
        "            max_iter=2,\n",
        "            memory=True\n",
        "        )\n",
        "\n",
        "        self.data_analyst = Agent(\n",
        "            role=\"Data Analysis Expert\",\n",
        "            goal=\"Analyze information and provide statistical insights\",\n",
        "            backstory=\"\"\"You are a skilled data analyst who excels at interpreting\n",
        "            complex information, identifying patterns, and creating actionable\n",
        "            recommendations based on data-driven insights.\"\"\",\n",
        "            llm=self.llm,\n",
        "            tools=[self.file_tool],\n",
        "            verbose=True,\n",
        "            allow_delegation=False,\n",
        "            max_iter=2,\n",
        "            memory=True\n",
        "        )\n",
        "\n",
        "        self.content_creator = Agent(\n",
        "            role=\"Content Strategy Expert\",\n",
        "            goal=\"Transform research into engaging, accessible content\",\n",
        "            backstory=\"\"\"You are a creative content strategist who excels at\n",
        "            transforming complex research and analysis into clear, engaging\n",
        "            content that resonates with target audiences.\"\"\",\n",
        "            llm=self.llm,\n",
        "            tools=[self.file_tool],\n",
        "            verbose=True,\n",
        "            allow_delegation=False,\n",
        "            max_iter=2,\n",
        "            memory=True\n",
        "        )\n",
        "\n",
        "        self.qa_agent = Agent(\n",
        "            role=\"Quality Assurance Specialist\",\n",
        "            goal=\"Ensure high-quality, accurate, and coherent deliverables\",\n",
        "            backstory=\"\"\"You are a meticulous quality assurance expert who ensures\n",
        "            all deliverables meet high standards of accuracy, clarity, and coherence.\"\"\",\n",
        "            llm=self.llm,\n",
        "            tools=[self.file_tool],\n",
        "            verbose=True,\n",
        "            allow_delegation=False,\n",
        "            max_iter=1,\n",
        "            memory=True\n",
        "        )\n",
        "\n",
        "        print(\"🤖 All agents initialized successfully!\")\n",
        "\n",
        "    def create_colab_tasks(self, topic, task_type=\"comprehensive\"):\n",
        "        \"\"\"Create optimized tasks for Colab environment\"\"\"\n",
        "\n",
        "        if task_type == \"comprehensive\":\n",
        "            return self._create_comprehensive_tasks(topic)\n",
        "        elif task_type == \"quick\":\n",
        "            return self._create_quick_tasks(topic)\n",
        "        elif task_type == \"analysis\":\n",
        "            return self._create_analysis_tasks(topic)\n",
        "        else:\n",
        "            return self._create_comprehensive_tasks(topic)\n",
        "\n",
        "    def _create_comprehensive_tasks(self, topic):\n",
        "        \"\"\"Create comprehensive research tasks\"\"\"\n",
        "\n",
        "        research_task = Task(\n",
        "            description=f\"\"\"\n",
        "            Research the topic: {topic}\n",
        "\n",
        "            Provide a comprehensive analysis including:\n",
        "            1. Key concepts and definitions\n",
        "            2. Current trends and developments\n",
        "            3. Main challenges and opportunities\n",
        "            4. Future outlook and implications\n",
        "\n",
        "            Format your response in clear sections with bullet points.\n",
        "            \"\"\",\n",
        "            agent=self.researcher,\n",
        "            expected_output=\"Structured research report with clear sections and key insights\"\n",
        "        )\n",
        "\n",
        "        analysis_task = Task(\n",
        "            description=f\"\"\"\n",
        "            Analyze the research findings for: {topic}\n",
        "\n",
        "            Provide:\n",
        "            1. Key insights and patterns\n",
        "            2. Statistical observations (if applicable)\n",
        "            3. Comparative analysis\n",
        "            4. Actionable recommendations\n",
        "            5. Risk assessment\n",
        "\n",
        "            Present findings in a clear, analytical format.\n",
        "            \"\"\",\n",
        "            agent=self.data_analyst,\n",
        "            expected_output=\"Analytical report with insights and recommendations\",\n",
        "            context=[research_task]\n",
        "        )\n",
        "\n",
        "        content_task = Task(\n",
        "            description=f\"\"\"\n",
        "            Create engaging content about: {topic}\n",
        "\n",
        "            Based on research and analysis, create:\n",
        "            1. Executive summary (2-3 paragraphs)\n",
        "            2. Key takeaways (5-7 bullet points)\n",
        "            3. Actionable recommendations\n",
        "            4. Future implications\n",
        "\n",
        "            Make it accessible and engaging for a general audience.\n",
        "            \"\"\",\n",
        "            agent=self.content_creator,\n",
        "            expected_output=\"Engaging, well-structured content for general audience\",\n",
        "            context=[research_task, analysis_task]\n",
        "        )\n",
        "\n",
        "        qa_task = Task(\n",
        "            description=f\"\"\"\n",
        "            Review and improve all content for: {topic}\n",
        "\n",
        "            Ensure:\n",
        "            1. Accuracy and consistency\n",
        "            2. Clear structure and flow\n",
        "            3. Completeness of information\n",
        "            4. Readability and engagement\n",
        "\n",
        "            Provide the final polished version.\n",
        "            \"\"\",\n",
        "            agent=self.qa_agent,\n",
        "            expected_output=\"Final polished content with quality improvements\",\n",
        "            context=[research_task, analysis_task, content_task]\n",
        "        )\n",
        "\n",
        "        return [research_task, analysis_task, content_task, qa_task]\n",
        "\n",
        "    def _create_quick_tasks(self, topic):\n",
        "        \"\"\"Create quick analysis tasks for faster execution\"\"\"\n",
        "\n",
        "        quick_research = Task(\n",
        "            description=f\"\"\"\n",
        "            Provide a quick but thorough analysis of: {topic}\n",
        "\n",
        "            Include:\n",
        "            1. Brief overview and key points\n",
        "            2. Main benefits and challenges\n",
        "            3. Current status and trends\n",
        "            4. Quick recommendations\n",
        "\n",
        "            Keep it concise but informative.\n",
        "            \"\"\",\n",
        "            agent=self.researcher,\n",
        "            expected_output=\"Concise analysis with key insights\"\n",
        "        )\n",
        "\n",
        "        quick_content = Task(\n",
        "            description=f\"\"\"\n",
        "            Create a summary report for: {topic}\n",
        "\n",
        "            Format:\n",
        "            1. Executive summary\n",
        "            2. Key findings (3-5 points)\n",
        "            3. Recommendations (3-5 points)\n",
        "            4. Next steps\n",
        "\n",
        "            Make it actionable and clear.\n",
        "            \"\"\",\n",
        "            agent=self.content_creator,\n",
        "            expected_output=\"Clear summary report with actionable insights\",\n",
        "            context=[quick_research]\n",
        "        )\n",
        "\n",
        "        return [quick_research, quick_content]\n",
        "\n",
        "    def _create_analysis_tasks(self, topic):\n",
        "        \"\"\"Create analysis-focused tasks\"\"\"\n",
        "\n",
        "        deep_analysis = Task(\n",
        "            description=f\"\"\"\n",
        "            Perform deep analysis of: {topic}\n",
        "\n",
        "            Focus on:\n",
        "            1. Detailed examination of key components\n",
        "            2. Pros and cons analysis\n",
        "            3. Comparative evaluation\n",
        "            4. Strategic implications\n",
        "            5. Data-driven conclusions\n",
        "\n",
        "            Provide thorough analytical insights.\n",
        "            \"\"\",\n",
        "            agent=self.data_analyst,\n",
        "            expected_output=\"Deep analytical report with detailed insights\"\n",
        "        )\n",
        "\n",
        "        return [deep_analysis]\n",
        "\n",
        "    def execute_colab_project(self, topic, task_type=\"comprehensive\", save_results=True):\n",
        "        \"\"\"Execute project optimized for Colab\"\"\"\n",
        "\n",
        "        print(f\"\\n🚀 Starting Colab AI Agent Project\")\n",
        "        print(f\"📋 Topic: {topic}\")\n",
        "        print(f\"🔧 Task Type: {task_type}\")\n",
        "        print(\"=\" * 60)\n",
        "\n",
        "        start_time = time.time()\n",
        "\n",
        "        try:\n",
        "            tasks = self.create_colab_tasks(topic, task_type)\n",
        "\n",
        "            if task_type == \"quick\":\n",
        "                agents = [self.researcher, self.content_creator]\n",
        "            elif task_type == \"analysis\":\n",
        "                agents = [self.data_analyst]\n",
        "            else:\n",
        "                agents = [self.researcher, self.data_analyst, self.content_creator, self.qa_agent]\n",
        "\n",
        "            crew = Crew(\n",
        "                agents=agents,\n",
        "                tasks=tasks,\n",
        "                process=Process.sequential,\n",
        "                verbose=1,\n",
        "                memory=True,\n",
        "                max_rpm=20\n",
        "            )\n",
        "\n",
        "            result = crew.kickoff()\n",
        "\n",
        "            execution_time = time.time() - start_time\n",
        "\n",
        "            print(f\"\\n✅ Project completed in {execution_time:.2f} seconds!\")\n",
        "            print(\"=\" * 60)\n",
        "\n",
        "            if save_results:\n",
        "                self._save_results(topic, task_type, result, execution_time)\n",
        "\n",
        "            return result\n",
        "\n",
        "        except Exception as e:\n",
        "            print(f\"\\n❌ Project execution failed: {str(e)}\")\n",
        "            print(\"💡 Try using 'quick' task type for faster execution\")\n",
        "            return None\n",
        "\n",
        "    def _save_results(self, topic, task_type, result, execution_time):\n",
        "        \"\"\"Save results to history\"\"\"\n",
        "        result_entry = {\n",
        "            'timestamp': datetime.now().isoformat(),\n",
        "            'topic': topic,\n",
        "            'task_type': task_type,\n",
        "            'execution_time': execution_time,\n",
        "            'result': str(result)\n",
        "        }\n",
        "\n",
        "        self.results_history.append(result_entry)\n",
        "\n",
        "        try:\n",
        "            with open('colab_agent_results.json', 'w') as f:\n",
        "                json.dump(self.results_history, f, indent=2)\n",
        "            print(\"💾 Results saved to colab_agent_results.json\")\n",
        "        except Exception as e:\n",
        "            print(f\"⚠️ Could not save results: {e}\")\n",
        "\n",
        "    def show_results_history(self):\n",
        "        \"\"\"Display results history\"\"\"\n",
        "        if not self.results_history:\n",
        "            print(\"📭 No results history available\")\n",
        "            return\n",
        "\n",
        "        print(\"\\n📊 Results History:\")\n",
        "        print(\"=\" * 50)\n",
        "\n",
        "        for i, entry in enumerate(self.results_history, 1):\n",
        "            print(f\"\\n{i}. Topic: {entry['topic']}\")\n",
        "            print(f\"   Task Type: {entry['task_type']}\")\n",
        "            print(f\"   Execution Time: {entry['execution_time']:.2f}s\")\n",
        "            print(f\"   Timestamp: {entry['timestamp']}\")\n",
        "            print(\"-\" * 30)\n",
        "\n",
        "    def create_custom_agent(self, role, goal, backstory, max_iter=2):\n",
        "        \"\"\"Create a custom agent\"\"\"\n",
        "        return Agent(\n",
        "            role=role,\n",
        "            goal=goal,\n",
        "            backstory=backstory,\n",
        "            llm=self.llm,\n",
        "            tools=[self.file_tool],\n",
        "            verbose=True,\n",
        "            allow_delegation=False,\n",
        "            max_iter=max_iter,\n",
        "            memory=True\n",
        "        )"
      ],
      "metadata": {
        "id": "com0ezEJu_wa"
      },
      "execution_count": 9,
      "outputs": []
    },
    {
      "cell_type": "code",
      "source": [
        "print(\"🔧 Initializing Colab AI Agent System...\")\n",
        "try:\n",
        "    agent_system = ColabGeminiAgentSystem(GEMINI_API_KEY)\n",
        "    print(\"✅ System ready for use!\")\n",
        "except Exception as e:\n",
        "    print(f\"❌ System initialization failed: {e}\")\n",
        "    print(\"Please check your API key and try again.\")"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 312
        },
        "id": "-rqxjx_LvQUQ",
        "outputId": "65c41643-54b0-44ce-ad23-abfa4a587d20"
      },
      "execution_count": 10,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "🔧 Initializing Colab AI Agent System...\n",
            "✅ Gemini API connection successful!\n",
            "🛠️ Tools initialized successfully!\n",
            "\n",
            "\n",
            "\n",
            "\n",
            "\n",
            "\n",
            "\n",
            "\n",
            "\n",
            "\n",
            "\n",
            "\n",
            "🤖 All agents initialized successfully!\n",
            "✅ System ready for use!\n"
          ]
        }
      ]
    },
    {
      "cell_type": "code",
      "source": [
        "def run_quick_examples():\n",
        "    \"\"\"Run quick examples to demonstrate the system\"\"\"\n",
        "\n",
        "    print(\"\\n🎯 Quick Start Examples\")\n",
        "    print(\"=\" * 40)\n",
        "\n",
        "    print(\"\\n1. Quick Analysis Example:\")\n",
        "    topic1 = \"Machine Learning in Business\"\n",
        "    result1 = agent_system.execute_colab_project(topic1, task_type=\"quick\")\n",
        "\n",
        "    if result1:\n",
        "        print(f\"\\n📋 Quick Analysis Result:\")\n",
        "        print(result1)\n",
        "\n",
        "    print(\"\\n2. Deep Analysis Example:\")\n",
        "    topic2 = \"Sustainable Energy Solutions\"\n",
        "    result2 = agent_system.execute_colab_project(topic2, task_type=\"analysis\")\n",
        "\n",
        "    if result2:\n",
        "        print(f\"\\n📋 Deep Analysis Result:\")\n",
        "        print(result2)"
      ],
      "metadata": {
        "id": "oySQyBLAvT0Z"
      },
      "execution_count": 11,
      "outputs": []
    },
    {
      "cell_type": "code",
      "source": [
        "def interactive_agent_system():\n",
        "    \"\"\"Interactive interface for the agent system\"\"\"\n",
        "\n",
        "    print(\"\\n🎮 Interactive AI Agent System\")\n",
        "    print(\"=\" * 40)\n",
        "    print(\"Available commands:\")\n",
        "    print(\"1. 'research [topic]' - Comprehensive research\")\n",
        "    print(\"2. 'quick [topic]' - Quick analysis\")\n",
        "    print(\"3. 'analyze [topic]' - Deep analysis\")\n",
        "    print(\"4. 'history' - Show results history\")\n",
        "    print(\"5. 'help' - Show this help\")\n",
        "    print(\"6. 'exit' - Exit the system\")\n",
        "    print(\"=\" * 40)\n",
        "\n",
        "    while True:\n",
        "        try:\n",
        "            command = input(\"\\n🤖 Enter command: \").strip().lower()\n",
        "\n",
        "            if command == 'exit':\n",
        "                print(\"👋 Goodbye!\")\n",
        "                break\n",
        "            elif command == 'help':\n",
        "                print(\"\\nAvailable commands:\")\n",
        "                print(\"- research [topic] - Comprehensive research\")\n",
        "                print(\"- quick [topic] - Quick analysis\")\n",
        "                print(\"- analyze [topic] - Deep analysis\")\n",
        "                print(\"- history - Show results history\")\n",
        "                print(\"- exit - Exit the system\")\n",
        "            elif command == 'history':\n",
        "                agent_system.show_results_history()\n",
        "            elif command.startswith('research '):\n",
        "                topic = command[9:]\n",
        "                agent_system.execute_colab_project(topic, task_type=\"comprehensive\")\n",
        "            elif command.startswith('quick '):\n",
        "                topic = command[6:]\n",
        "                agent_system.execute_colab_project(topic, task_type=\"quick\")\n",
        "            elif command.startswith('analyze '):\n",
        "                topic = command[8:]\n",
        "                agent_system.execute_colab_project(topic, task_type=\"analysis\")\n",
        "            else:\n",
        "                print(\"❌ Unknown command. Type 'help' for available commands.\")\n",
        "\n",
        "        except KeyboardInterrupt:\n",
        "            print(\"\\n👋 System interrupted. Goodbye!\")\n",
        "            break\n",
        "        except Exception as e:\n",
        "            print(f\"❌ Error: {e}\")"
      ],
      "metadata": {
        "id": "mXCrU3nXvXxi"
      },
      "execution_count": 12,
      "outputs": []
    },
    {
      "cell_type": "code",
      "source": [
        "class ColabUtils:\n",
        "    \"\"\"Utility functions for Colab\"\"\"\n",
        "\n",
        "    @staticmethod\n",
        "    def download_results():\n",
        "        \"\"\"Download results file\"\"\"\n",
        "        try:\n",
        "            from google.colab import files\n",
        "            files.download('colab_agent_results.json')\n",
        "            print(\"📥 Results file downloaded!\")\n",
        "        except Exception as e:\n",
        "            print(f\"❌ Download failed: {e}\")\n",
        "\n",
        "    @staticmethod\n",
        "    def display_formatted_result(result):\n",
        "        \"\"\"Display result in formatted way\"\"\"\n",
        "        from IPython.display import display, Markdown\n",
        "\n",
        "        if isinstance(result, str):\n",
        "            display(Markdown(f\"### AI Agent Result\\n\\n{result}\"))\n",
        "        else:\n",
        "            display(Markdown(f\"### AI Agent Result\\n\\n{str(result)}\"))\n",
        "\n",
        "    @staticmethod\n",
        "    def save_to_drive():\n",
        "        \"\"\"Save results to Google Drive\"\"\"\n",
        "        try:\n",
        "            from google.colab import drive\n",
        "            drive.mount('/content/drive')\n",
        "\n",
        "            import shutil\n",
        "            shutil.copy('colab_agent_results.json', '/content/drive/MyDrive/agent_results.json')\n",
        "            print(\"💾 Results saved to Google Drive!\")\n",
        "        except Exception as e:\n",
        "            print(f\"❌ Drive save failed: {e}\")"
      ],
      "metadata": {
        "id": "StgeKxHUvawx"
      },
      "execution_count": 13,
      "outputs": []
    },
    {
      "cell_type": "code",
      "execution_count": 14,
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "syJ9V-ispJE8",
        "outputId": "037808ef-7cd1-40f9-a041-1ddb10e85b43"
      },
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "\n",
            "🎉 Google Colab AI Agent System Ready!\n",
            "\n",
            "📖 How to use:\n",
            "\n",
            "1. **Quick Start**:\n",
            "   ```python\n",
            "   result = agent_system.execute_colab_project(\"Your Topic\", task_type=\"quick\")\n",
            "   ```\n",
            "\n",
            "2. **Comprehensive Analysis**:\n",
            "   ```python\n",
            "   result = agent_system.execute_colab_project(\"Your Topic\", task_type=\"comprehensive\")\n",
            "   ```\n",
            "\n",
            "3. **Deep Analysis**:\n",
            "   ```python\n",
            "   result = agent_system.execute_colab_project(\"Your Topic\", task_type=\"analysis\")\n",
            "   ```\n",
            "\n",
            "4. **Interactive Mode**:\n",
            "   ```python\n",
            "   interactive_agent_system()\n",
            "   ```\n",
            "\n",
            "5. **Run Demo**:\n",
            "   ```python\n",
            "   run_demo()\n",
            "   ```\n",
            "\n",
            "6. **View History**:\n",
            "   ```python\n",
            "   agent_system.show_results_history()\n",
            "   ```\n",
            "\n",
            "7. **Download Results**:\n",
            "   ```python\n",
            "   ColabUtils.download_results()\n",
            "   ```\n",
            "\n",
            "🚀 **Example Usage**:\n",
            "```python\n",
            "# Quick analysis\n",
            "result = agent_system.execute_colab_project(\"Machine Learning Trends\", \"quick\")\n",
            "print(result)\n",
            "\n",
            "# Show formatted result\n",
            "ColabUtils.display_formatted_result(result)\n",
            "```\n",
            "\n",
            "💡 **Tips for Colab**:\n",
            "- Use \"quick\" task type for faster execution\n",
            "- Results are automatically saved\n",
            "- Use ColabUtils for better formatting\n",
            "- Download results before closing the session\n",
            "\n",
            "🔧 **Troubleshooting**:\n",
            "- If you get API errors, check your rate limits\n",
            "- For memory issues, restart runtime\n",
            "- Use quick tasks for better performance\n",
            "\n"
          ]
        }
      ],
      "source": [
        "def run_demo():\n",
        "    \"\"\"Run a comprehensive demo\"\"\"\n",
        "\n",
        "    print(\"\\n🎬 AI Agent System Demo\")\n",
        "    print(\"=\" * 50)\n",
        "\n",
        "    demo_topics = [\n",
        "        (\"Artificial Intelligence Ethics\", \"quick\"),\n",
        "        (\"Climate Change Solutions\", \"analysis\"),\n",
        "        (\"Future of Work\", \"comprehensive\")\n",
        "    ]\n",
        "\n",
        "    for topic, task_type in demo_topics:\n",
        "        print(f\"\\n🎯 Demo: {topic} ({task_type})\")\n",
        "        result = agent_system.execute_colab_project(topic, task_type)\n",
        "\n",
        "        if result:\n",
        "            ColabUtils.display_formatted_result(result)\n",
        "\n",
        "        time.sleep(2)\n",
        "\n",
        "print(\"\"\"\n",
        "🎉 Google Colab AI Agent System Ready!\n",
        "\n",
        "📖 How to use:\n",
        "\n",
        "1. **Quick Start**:\n",
        "   ```python\n",
        "   result = agent_system.execute_colab_project(\"Your Topic\", task_type=\"quick\")\n",
        "   ```\n",
        "\n",
        "2. **Comprehensive Analysis**:\n",
        "   ```python\n",
        "   result = agent_system.execute_colab_project(\"Your Topic\", task_type=\"comprehensive\")\n",
        "   ```\n",
        "\n",
        "3. **Deep Analysis**:\n",
        "   ```python\n",
        "   result = agent_system.execute_colab_project(\"Your Topic\", task_type=\"analysis\")\n",
        "   ```\n",
        "\n",
        "4. **Interactive Mode**:\n",
        "   ```python\n",
        "   interactive_agent_system()\n",
        "   ```\n",
        "\n",
        "5. **Run Demo**:\n",
        "   ```python\n",
        "   run_demo()\n",
        "   ```\n",
        "\n",
        "6. **View History**:\n",
        "   ```python\n",
        "   agent_system.show_results_history()\n",
        "   ```\n",
        "\n",
        "7. **Download Results**:\n",
        "   ```python\n",
        "   ColabUtils.download_results()\n",
        "   ```\n",
        "\n",
        "🚀 **Example Usage**:\n",
        "```python\n",
        "# Quick analysis\n",
        "result = agent_system.execute_colab_project(\"Machine Learning Trends\", \"quick\")\n",
        "print(result)\n",
        "\n",
        "# Show formatted result\n",
        "ColabUtils.display_formatted_result(result)\n",
        "```\n",
        "\n",
        "💡 **Tips for Colab**:\n",
        "- Use \"quick\" task type for faster execution\n",
        "- Results are automatically saved\n",
        "- Use ColabUtils for better formatting\n",
        "- Download results before closing the session\n",
        "\n",
        "🔧 **Troubleshooting**:\n",
        "- If you get API errors, check your rate limits\n",
        "- For memory issues, restart runtime\n",
        "- Use quick tasks for better performance\n",
        "\"\"\")"
      ]
    }
  ]
}